package com.voxel.sense.infomsg.utils.marker.cluster.strategy;

import com.amap.api.maps.model.LatLng;
import cyy.example.com.facotry.model.api.response.MissionLocationEntity;

import com.voxel.sense.infomsg.utils.cover.EntityConvertStrategy;
import com.voxel.sense.infomsg.utils.marker.cluster.data.ClusterItem;
import com.voxel.sense.infomsg.utils.marker.cluster.data.RegionItem;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by ChenYiYao on 2018/6/11.
 */
public class MissionConverStrategey implements EntityConvertStrategy<ClusterItem, MissionLocationEntity.BodyBean> {
    boolean isVisible = true;

    @Override
    public List<ClusterItem> convertEntity(List<MissionLocationEntity.BodyBean> list) {
        return convertEntity(list, "");
    }

    @Override
    public List<ClusterItem> convertEntity(List<MissionLocationEntity.BodyBean> list, String type) {
        if (list != null) {
            List<ClusterItem> regionItems = new ArrayList<>();
            convertFirmTypeNor(list, regionItems, type);
            return regionItems;
        }
        return null;
    }
//    List<MissionLocationEntity.BodyBean> list

    private void convertFirmTypeNor(List<MissionLocationEntity.BodyBean> list, List<ClusterItem> regionItems, String type) {
        List<MissionLocationEntity.BodyBean> beans = list;
        for (MissionLocationEntity.BodyBean bean : beans) {
            try {
                double latitude = Double.parseDouble(bean.getLatitude());
                double longitude = Double.parseDouble(bean.getLongitude());
                RegionItem item = new RegionItem(new LatLng(latitude, longitude), type, bean, isVisible);
                regionItems.add(item);
            } catch (NumberFormatException e) {
                e.printStackTrace();
            }
        }
    }

    public boolean isVisible() {
        return isVisible;
    }

    public void setVisible(boolean visible) {
        isVisible = visible;
    }
}
